class Task53:
    def run(self, array, n):
        first_index = self.get_first(array, n)
        last_index = self.get_last(array, n)
        if first_index is None or last_index is None:
            return 0
        else:
            return last_index - first_index + 1

    def get_first(self, array, n):
        start = 0
        end = len(array)
        while start < end:
            index = (start + end) // 2
            if array[index] == n:
                if index == 0 or array[index - 1] != n:
                    return index
                else:
                    end = index
            elif array[index] > n:
                end = index
            else:
                start = index + 1
        return None

    def get_last(self, array, n):
        start = 0
        end = len(array)
        while start < end:
            index = (start + end) // 2
            if array[index] == n:
                if index == len(array) - 1 or array[index + 1] != n:
                    return index
                else:
                    start = index + 1
            elif array[index] > n:
                end = index
            else:
                start = index + 1
        return None
